import request from '@/utils/request'
import type { ApiResponse } from '@/types/api'
import type { RegionItem } from '@/api/system/region'

// 获取地区列表
export function getRegionList(params: any): Promise<ApiResponse<RegionItem[]>> {
  return request({
    url: '/api/system/region',
    method: 'get',
    params,
  })
}

// 获取树形地区结构
export function getRegionTree(params: any): Promise<ApiResponse<RegionItem[]>> {
  return request({
    url: '/api/system/region/tree',
    method: 'get',
    params,
  })
}

// 查看地区详情
export function getRegionView(id: number): Promise<ApiResponse<RegionItem>> {
  return request({
    url: '/api/system/region/view',
    method: 'get',
    params: { id },
  })
}

// 新增地区
export function addRegion(data: Partial<RegionItem>): Promise<ApiResponse<any>> {
  return request({
    url: '/api/system/region/add',
    method: 'post',
    data,
  })
}

// 编辑地区
export function editRegion(data: Partial<RegionItem>): Promise<ApiResponse<any>> {
  return request({
    url: '/api/system/region/edit',
    method: 'post',
    data,
  })
}

// 删除地区
export function deleteRegion(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/system/region/del',
    method: 'post',
    data: { id },
  })
}

// 获取启用地区列表
export function getActiveRegionList(): Promise<ApiResponse<RegionItem[]>> {
  return request({
    url: '/api/system/region/set',
    method: 'get',
  })
}

// 设置地区状态
export function setRegionStatus(data: { id: number; status: number }): Promise<ApiResponse<any>> {
  return request({
    url: '/api/system/region/set_status',
    method: 'post',
    data,
  })
}
